//
//  HD_NKM_RootVC+Tableview.m
//  HDLiaoNingMeseum
//
//  Created by HDNiuKuiming on 2017/8/3.
//  Copyright © 2017年 HDNiuKuiming. All rights reserved.
//

#import "HD_NKM_RootVC+Tableview.h"
#import "HDRootCellA.h"
#import "HDRootCellB.h"

@implementation HD_NKM_RootVC (Tableview)

- (void)reloadTableView
{
//    dispatch_async(dispatch_get_main_queue(), ^{
//        myTableView.delegate = self;
//        myTableView.dataSource = self;
//        [myTableView reloadData];
//    });
}

#pragma mark
#pragma mark -------- TableView Methods -------
#define Row_Num 4

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return Row_Num;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger nowIndex = indexPath.row;
    NSString *identifier = @"cellIndex00";
    if (nowIndex >= 3)
        identifier = @"cellIndex10";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil)
    {
        if (nowIndex < 3)
            cell = [[HDRootCellA alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        else
            cell = [[HDRootCellB alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
    }
    
    NSString *btnSuffix = @"";
    HDDeclare *declare = [HDDeclare sharedDeclare];
    if (declare.languageIndex == kLanguage_Type_English)
        btnSuffix = @"_E";
    else if (declare.languageIndex == kLanguage_Type_Japanese)
        btnSuffix = @"_J";
    else if (declare.languageIndex == kLanguage_Type_Korean)
        btnSuffix = @"_K";
    
    if(nowIndex < 3) {
        HDRootCellA *cellA = (HDRootCellA*)cell;
        NSString *bgImageName = [NSString stringWithFormat:@"%@",self.cellImageArray[nowIndex]];
        NSString *iconImageName = [NSString stringWithFormat:@"%@_img%@",bgImageName,btnSuffix];
        cellA.bgImageView.image = [UIImage imageNamed:bgImageName];
        cellA.iconImageView.image = [UIImage imageNamed:iconImageName];
        
        UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell_selected"]];
        cell.selectedBackgroundView = image;
    }
    else {
        HDRootCellB *cellB = (HDRootCellB*)cell;
        cellB.selectionStyle = UITableViewCellSelectionStyleNone;
        
        NSString *bgImageNameLeft = [NSString stringWithFormat:@"%@",self.cellImageArray[nowIndex]];
        NSString *bgImageNameRight = [NSString stringWithFormat:@"%@",self.cellImageArray[nowIndex+1]];
        NSString *iconImageNameLeft = [NSString stringWithFormat:@"%@_img%@",bgImageNameLeft,btnSuffix];
        NSString *iconImageNameRight = [NSString stringWithFormat:@"%@_img%@",bgImageNameRight,btnSuffix];
        
        cellB.bgImageLeft.image = [UIImage imageNamed:bgImageNameLeft];
        cellB.bgImgeRight.image = [UIImage imageNamed:bgImageNameRight];
        [cellB.btnLetf setImage:[UIImage imageNamed:iconImageNameLeft] forState:UIControlStateNormal];
        [cellB.btnRight setImage:[UIImage imageNamed:iconImageNameRight] forState:UIControlStateNormal];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger selectedIndex = indexPath.row;
    if (selectedIndex == 3)
        return;
    
    NSString *pushLineName = @"pushToRelicsLine";
    switch (selectedIndex) {
        case 1:
            pushLineName = @"pushToMapLine";
            break;
            
        case 2:
            pushLineName = @"pushToAutoGuideLine";
            break;
            
        default:
            break;
    }
    [self performSegueWithIdentifier:pushLineName sender:nil];
}

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    if ([identifier isEqualToString:@"pushToMineLine"] || [identifier isEqualToString:@"pushToHelpLine"]) {
        if ([[HDDeclare sharedDeclare] netStatus] != YES) {
            [LCCoolHUD showFailure:@"网络失败" zoom:NO shadow:NO];
            return NO;
        }
        
        return YES;
    }
    
    return YES;
}


@end
